package com.hljx.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.hljx.config.Result;
import com.hljx.dto.WorkloadTargetAdministrationCopyDTO;
import com.hljx.dto.WorkloadTargetAdministrationDTO;
import com.hljx.dto.WorkloadTargetAdministrationInsertDTO;
import com.hljx.entity.WorkloadTargetAdministration;
import com.hljx.mapper.sys.WorkloadTargetAdministrationMapper;
import com.hljx.service.WorkloadTargetAdministrationService;
import com.hljx.vo.ProjectTargetVO;
import com.hljx.vo.WorkloadTargetAdministrationDeptProjectVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 工作量指标管理主表 前端控制器
 * </p>
 *
 * @author hxc
 * @since 2023-09-18
 */
@Tag(name = "工作量指标管理")
@RestController
@RequestMapping("/workloadTargetAdministration")
public class WorkloadTargetAdministrationController {

    @Autowired
    private WorkloadTargetAdministrationService workloadTargetAdministrationService;
    @Autowired
    private WorkloadTargetAdministrationMapper workloadTargetAdministrationMapper;
    @PostMapping("/listByPageAdministration")
    @Operation(summary = "分页模糊查询")
    public Result listByPageAdministration(@RequestBody WorkloadTargetAdministrationDTO workloadTargetAdministrationDTO){
        IPage<WorkloadTargetAdministrationDeptProjectVO> workloadTargetAdministrationDeptProjectVOIPage = workloadTargetAdministrationService.listByPage(workloadTargetAdministrationDTO);
        return Result.success(workloadTargetAdministrationDeptProjectVOIPage);
    }


    @PostMapping("/insertWorkloadTargetAdministration")
    @Operation(summary = "新增工作量指标管理")
    public Result insertWorkloadTargetAdministration(@RequestBody WorkloadTargetAdministrationInsertDTO insertDTO){
        int i = workloadTargetAdministrationService.insertWorkloadTargetAdministration(insertDTO);
        return i != 0 ? Result.success() : Result.failed();
    }


    @GetMapping("/updateWorkloadTargetAdministrationInfo")
    @Operation(summary = "编辑回显")
    public Result updateWorkloadTargetAdministrationInfo(String period,Long id){
        WorkloadTargetAdministrationDeptProjectVO workloadTargetAdministrationDeptProjectVOS = workloadTargetAdministrationService.updateWorkloadTargetAdministrationInfo(period, id);
        return Result.success(workloadTargetAdministrationDeptProjectVOS);
    }


    @PostMapping("/updateWorkloadTargetAdministration")
    @Operation(summary = "编辑工作量指标管理")
    public Result updateWorkloadTargetAdministration(@RequestBody WorkloadTargetAdministrationInsertDTO updateDTO){
        int i = workloadTargetAdministrationService.updateWorkloadTargetAdministration(updateDTO);
        return i != 0 ? Result.success() : Result.failed();
    }


    @PostMapping("/inherit")
    @Operation(summary = "继承")
    public Result inherit(@RequestBody WorkloadTargetAdministrationCopyDTO copyDTO){
        int i = workloadTargetAdministrationService.inheritWorkloadTargetAdministration(copyDTO);
        return i != 0 ? Result.success() : Result.failed();
    }


    @GetMapping("/deleteWorkloadAdministration")
    @Operation(summary = "删除")
    public Result deleteWorkloadAdministration(Long id,String period){
        WorkloadTargetAdministrationDTO workloadTargetAdministrationDTO = new WorkloadTargetAdministrationDTO();
        workloadTargetAdministrationDTO.setId(id);
        workloadTargetAdministrationDTO.setPeriod(period);
        int i = workloadTargetAdministrationService.deleteWorkloadAdministration(workloadTargetAdministrationDTO);
        return i != 0 ? Result.success() : Result.failed();
    }


    @GetMapping("/listByPeriod")
    @Operation(summary = "根据周期查询工作量指标")
    public Result<List<WorkloadTargetAdministration>> listByPeriod(@RequestParam String  period){
        List<WorkloadTargetAdministration> workloadTargetAdministrations = workloadTargetAdministrationMapper.listByPerid(period);
        return Result.success(workloadTargetAdministrations);
    }





}
